home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / c_math.arc / ASIN.C next >
Text File  |  1983-07-02  |  716b  |  49 lines

  1. /*
  2.     asin(arg) and acos(arg) return the arcsin, arccos,
  3.     respectively of their arguments.
  4.  
  5.     Arctan is called after appropriate range reduction.
  6. */
  7.  
  8. #include    <errno.h>
  9. int errno;
  10. double atan();
  11. double sqrt();
  12. static double pio2    = 1.570796326794896619;
  13.  
  14. double
  15. asin(arg) double arg; {
  16.  
  17.     double sign, temp;
  18.  
  19.     sign = 1.;
  20.     if(arg <0){
  21.         arg = -arg;
  22.         sign = -1.;
  23.     }
  24.  
  25.     if(arg > 1.){
  26.         errno = EDOM;
  27.         return(0.);
  28.     }
  29.  
  30.     temp = sqrt(1. - arg*arg);
  31.     if(arg > 0.7)
  32.         temp = pio2 - atan(temp/arg);
  33.     else
  34.         temp = atan(arg/temp);
  35.  
  36.     return(sign*temp);
  37. }
  38.  
  39. double
  40. acos(arg) double arg; {
  41.  
  42.     if((arg > 1.) || (arg < -1.)){
  43.         errno = EDOM;
  44.         return(0.);
  45.     }
  46.  
  47.     return(pio2 - asin(arg));
  48. }
  49.